using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Xeneize.SolaraBL;

namespace WIntegrator.Controls
{
    public partial class AddComment : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Button1.Enabled = true;
            FillCombo();
        }

        private void FillCombo()
        {
            //Fill User Combo
            User user = new User();
            this.cbAssignTo.DataSource = user.GetUserList();
            this.cbAssignTo.DataBind();
            user = null;

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (this.txtComment.Text == string.Empty)
                return;
            string orderID = Request.QueryString["id"].ToString();
            OrderComment comment = new OrderComment();
            comment.Text = this.txtComment.Text;
            comment.IsRedFlag = (Convert.ToInt32(this.cbRedFlag.SelectedValue) ==0)? false:true;
            comment.DatePosted = DateTime.Today;
            comment.Owner = new User(Membership.GetUser().ProviderUserKey.ToString()).Name;
            comment.AssignedTo = this.cbAssignTo.Text;
            SalesOrder order = new SalesOrder(orderID);
            order.InsertComment(comment);
            order = null;            
        }

        protected void cbAssignTo_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            if (this.cbAssignTo.SelectedIndex == 0 && this.cbRedFlag.SelectedValue.ToString() =="1")
                this.Button1.Enabled = false;            
        }

        protected void cbRedFlag_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            if (this.cbAssignTo.SelectedIndex == 0 && this.cbRedFlag.SelectedValue.ToString() == "1")
                this.Button1.Enabled = false;            
        }
    }
}
